package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpExpr;
import com.itheima.pojo.LoginInfo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
//    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
//    long getTotal();
//
//    @Select("select emp.* , d.name as deptName from emp left join dept d on emp.dept_id = d.id limit #{index} , #{pageSize}")
//    List<Emp> getRows(@Param("index") Integer index, @Param("pageSize") Integer pageSize);

    // @Select("select emp.* , dept.name as deptName from emp left join dept on emp.dept_id = dept.id")
    List<Emp> findAll(@Param("name") String name, @Param("gender") Integer gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    @Insert("insert into tlias.emp  (username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) values " +
            "(#{username} , #{name} , #{gender} , #{phone} , #{job} , #{salary} , #{image}  , #{entryDate} , #{deptId} , #{createTime} , #{updateTime}  )")
    @Options(useGeneratedKeys = true, keyProperty = "id")
        // 添加数据的主键回填到 emp 对象中的id成员变量上
    void insertEmp(Emp emp);


    void deleteEmp(@Param("ids") List<Integer> ids);

    Emp queryEmpById(Integer id);

    void updateEmp(Emp emp);

    /*
        {
            { job=教研主管 , number=1 } ,
            { job=学工主管 , number=1 } ,
            { job=其他 , number=1},
            { job=班主任 , number=6},
            { job=咨询师 , number=7},
            { job=讲师 , number=11},
        }
     */
    List<Map<String, Object>> calcJobCount();

    /*
        {
             {name=男性员工 , value=23} ,
             {name=女性员工 , value=4}

        }
     */
    List<Map<String, Object>> calcGenderCount();

    @Select("select * from emp")
    List<Emp> queryAllEmp();

    @Select("select * from emp where username = #{username} and password = #{password}")
    LoginInfo login(Emp emp);
}
